<template>
  <div class="page-container">
    <DynamicForm :config="dyConfig" :questions="dyQuestions" />
    <DynamicTable :tables="dyTable" :config="dyTableConfig" :icons="dyIcons" />
  </div>
</template>
<script lang="ts" setup>
import { getCurrentInstance, onBeforeUnmount, reactive } from 'vue';
import { DynamicForm, DynamicTable } from '@/components/public-template';
import indexService from './index.service';
import { Api } from '@/config/api/archivesFile';
import { filter } from 'rxjs/operators';
import { DYNAMICLOCALICONS } from '@/mixins/subject/subject-types';
import { useRouter } from 'vue-router';
import { message } from 'ant-design-vue';

const state = reactive({
  count: 1
});
const dyConfig: any = {
  name: 'inputTable',
  labelCol: 6,
  wrapperCol: 18,
  grid: 8,
  style: 'table-form',
  cancelSave: true
};
const dyTableConfig: any = {
  name: 'inputTable',
  queryUrl: Api.fileListPage,
  protType: 'post',
  isScreen: true,
  rowSelection: {
    type: 'checkbox'
  }
};
const dyQuestions: any = reactive(indexService.getQuestions());
const dyTable: any = reactive(indexService.getTables());
const dyIcons: any = reactive(indexService.getIcons());
// 监听table
const router = useRouter();
const { proxy }: any = getCurrentInstance();
const subscribeSub = proxy.$NotificationPubSub
  .getParams()
  .pipe(filter((res) => res !== 0))
  .subscribe((item: any) => {
    console.log('item', item);
    if (item.key === DYNAMICLOCALICONS) {
      if (!item.state.selected.length) return message.warning('请先选中一个选项');
      const params = { ids: item.state.selected.map((item) => item.id), filesTypeS: item.state.selected.map((item) => item.filesType) };
      router.push({
        name: 'ArchivesManageAddInput',
        state: { params }
      });
    }
  });
onBeforeUnmount(() => {
  subscribeSub && subscribeSub.unsubscribe();
  proxy.$NotificationPubSub.clearParams();
});
</script>

<style lang="less" scoped></style>
